package com.xu.t1.common;

import com.xu.t1.model.LearningRecord;
import org.springframework.stereotype.Component;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 * 生成模拟数据用于写入
 *
 * @author xu
 *
 */

@Component
public class RecordGenerator {

    private static final SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");

    public static List<LearningRecord> generateFixedRecords(int count) {
        List<LearningRecord> list = new ArrayList<>(count);
        Date fixedDate;
        try {
            fixedDate = sdf.parse("2025-01-01");
        } catch (ParseException e) {
            throw new RuntimeException("日期解析失败", e);
        }

        for (int i = 0; i < count; i++) {
            LearningRecord record = new LearningRecord();
            // id不赋值，保持为null
            record.setUserId(10L);
            record.setStudyDate(fixedDate);
            record.setStudyTime(30);
            record.setProgress(1000);
            record.setContent("测试内容" + (i + 1));
            record.setCreatedAt(fixedDate);

            list.add(record);
        }

        return list;
    }
}